package com.sharedlease.check;

import com.sharedlease.entity.Illegal;
import com.sharedlease.service.IllegalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
@Order(value = 1)
public class IllegalInfoInitialization implements CommandLineRunner {

    @Autowired
    public IllegalService illegalService;

    @Override
    public void run(String... args) throws Exception {
        new Thread(){
            @Override
            public void run() {
                // 读取数据库中违法信息标识 --> 到factory中
                Set<String> factory = new HashSet<>();
                List<Illegal> list = illegalService.list(null);
                for (Illegal x : list){
                    factory.add(x.getWord());
                }
                IllegalInfoFactory.setFactory(factory);
            }
        }.start();
    }

}
